package com.qw.badge.sample

import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.qw.badge.sample.databinding.ActivityMainBinding


class MainActivity : AppCompatActivity() {
    private lateinit var bind: ActivityMainBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        ActivityMainBinding.inflate(layoutInflater).apply {
            setContentView(this.root)
            bind = this
        }
        bind.mLauncherLabel.text = Badge.getHomePackage(this)
        bind.mEditText.setOnClickListener {

        }
        bind.mButton.setOnClickListener {
            val num = bind.mEditText.text.toString()
            if (num.trim().isEmpty()) return@setOnClickListener

            Handler(Looper.myLooper()!!).postDelayed({
                Badge.setBadgeNum(this, num.toInt())
            }, 3000)

        }
        bind.mClearButton.setOnClickListener {
            Badge.setBadgeNum(this, 0)
        }
        Log.d("MainActivity", Badge.getHomePackage(this))
    }
}